package stone;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;

public class ParseException extends Exception {
  public ParseException(Token t) {
    this("", t);
  }

  public ParseException(String msg, Token t) {
    super("syntax error around " + location(t) + ". " + msg);
  }

  @NotNull
  private static String location(Token t) {
    return t == Token.EOF
        ? "the last line"
        : "\"" + t.getText() + "\" at line " + t.getLineNumber();
  }

  public ParseException(IOException e) {
    super(e);
  }

  public ParseException(String msg) {
    super(msg);
  }
}
